home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlb20 / lib / _fixsfsi.cpp < prev    next >
Text File  |  1992-04-26  |  2KB  |  91 lines

  1. |
  2. |  single float to long conversion routine
  3. |
  4. | Andreas Schwab (schwab@ls5.informatik.uni-dortmund.de)
  5. |  mostly copied from _fixdfsi.cpp
  6. |  (error check removed because no checking possible)
  7.  
  8. #ifndef __M68881__
  9.  
  10.     .text
  11.     .even
  12.  
  13. #ifdef sfp004
  14.  
  15. comm =     -6
  16. resp =    -16
  17. zahl =      0
  18.  
  19.     .globl    ___fixsfsi
  20. ___fixdfsi:
  21.     lea    0xfffa50,a0
  22.     movew    #0x5403,a0@(comm)    | fintrz to fp0
  23.     cmpiw    #0x8900,a0@(resp)    | check
  24.     movel    a7@(4),a0@
  25.     movel    a7@(8),a0@
  26.     movew    #0x6000,a0@(comm)    | result to d0
  27. | waiting loop is NOT coded directly
  28. 1:    cmpiw    #0x8900,a0@(resp)
  29.     beq    1b
  30.     movel    a0@,d0
  31.         
  32. #else /* !sfp004 */
  33.  
  34. BIAS4    =    0x7F-1
  35.  
  36.     .globl    ___fixsfsi
  37. ___fixsfsi:
  38.     movel    sp@(4),d0    | get number
  39.     movel    d2,sp@-        | save register
  40.     movel    d0,d1
  41.     swap    d1        | extract exp
  42.     movew    d1,d2        | extract sign
  43.     lsrw    #7,d1
  44.     andw    #0xff,d1    | kill sign bit
  45.  
  46.     andl    #0x7fffff,d0    | remove exponent from mantissa
  47.     orl    #0x800000,d0    | restore implied leading "1"
  48.  
  49.     cmpw    #BIAS4,d1    | check exponent
  50.     blt    zero        | strictly factional, no integer part ?
  51.     cmpw    #BIAS4+32,d1    | is it too big to fit in a 32-bit integer ?
  52.     bgt    toobig
  53.  
  54.     subw    #BIAS4+24,d1    | adjust exponent
  55.     bgt    2f        | shift up
  56.     beq    7f        | no shift (never too big)
  57.  
  58. 1:    negw    d1
  59.     lsrl    d1,d0        | shift down to align radix point;
  60.                 | extra bits fall off the end (no rounding)
  61.     bra    7f        | never too big
  62.  
  63. 2:    lsll    d1,d0        | shift up to align radix point
  64.  
  65. 3:    cmpl    #0x80000000,d0    | -2147483648 is a nasty evil special case
  66.     bne    6f
  67.     tstw    d2        | this had better be -2^31 and not 2^31
  68.     bpl    toobig
  69.     bra    8f
  70. 6:    tstl    d0        | sign bit set ? (i.e. too big)
  71.     bmi    toobig
  72. 7:
  73.     tstw    d2        | is it negative ?
  74.     bpl    8f
  75.     negl    d0        | negate
  76. 8:
  77.     movel    sp@+,d2
  78.     rts
  79.  
  80. zero:
  81.     clrl    d0        | make the whole thing zero
  82.     bra    8b
  83.  
  84. toobig:
  85.     movel    #0x7fffffff,d0    | ugh. Should cause a trap here.
  86.     bra    8b
  87.  
  88. #endif /* !sfp004*/
  89.  
  90. #endif /* !__M68881__ */
  91.